package o;

import android.content.Context;
import android.os.Build.VERSION;
import android.os.StatFs;
import android.os.storage.StorageManager;
import android.os.storage.StorageVolume;
import android.text.TextUtils;
import java.io.File;
import java.lang.reflect.Method;
import o.cfl.e;

public final class epp {
    private static String ॱ = "appstoreLog.zip";

    public static String ˊ(Context context) {
        String str;
        if (Logger.ˎ()) {
            str = doc.ॱ(context) + "/Log/";
        } else {
            File filesDir = context.getFilesDir();
            if (filesDir == null) {
                return null;
            }
            str = filesDir.getAbsolutePath() + "/Log/";
        }
        File file = new File(str);
        if (file.exists() || file.mkdirs()) {
            return str;
        }
        return null;
    }

    public static String ॱ(Context context) {
        File filesDir = context.getFilesDir();
        if (filesDir == null) {
            return null;
        }
        String str = filesDir.getAbsolutePath() + "/upload/";
        File file = new File(str);
        if (file.exists() || file.mkdirs()) {
            return str;
        }
        return null;
    }

    public static String ˏ(Context context) {
        return ˊ(context) + ॱ;
    }

    public static cfl ˋ() {
        cfl ˎ;
        Context ˋ = ContentManager.getInstant().getContext();
        if (VERSION.SDK_INT >= 24 || eqh.ˎ().ˏ()) {
            ˎ = ˎ(ˋ);
        } else {
            ˎ = ˋ(ˋ);
        }
        if (TextUtils.isEmpty(ˎ.ˎ())) {
            return null;
        }
        String str = ˎ.ˎ() + File.separator;
        File file = new File(ˎ.ˎ() + "/AppCache/");
        if (file.exists() && !file.delete()) {
            Logger.e("StorageManage", "appcache is exist,but can not delete.");
        }
        ˎ.ˊ(str);
        File file2 = new File(str);
        if (!file2.exists() && !file2.mkdirs()) {
            return null;
        }
        if (VERSION.SDK_INT >= 24 || file2.setExecutable(true, false)) {
            return ˎ;
        }
        Logger.e("StorageManage", "can not set Executeable to AppCache");
        return ˎ;
    }

    public static cfl ˎ(Context context) {
        File filesDir = context.getFilesDir();
        cfl o_cfl = new cfl();
        if (filesDir != null) {
            String absolutePath = filesDir.getAbsolutePath();
            o_cfl.ˊ(ˎ(absolutePath));
            o_cfl.ˎ(ˋ(absolutePath));
            o_cfl.ˊ(absolutePath);
        }
        o_cfl.ॱ(e.SYSTEM_STORAGE);
        return o_cfl;
    }

    public static cfl ˋ(Context context) {
        File file = new File(ʻ(context) + File.separator + context.getPackageName() + File.separator + "files");
        if (!(file.exists() || file.mkdirs())) {
            Logger.e("StorageManage", "failed to create file.");
        }
        cfl o_cfl = new cfl();
        String absolutePath = file.getAbsolutePath();
        o_cfl.ˊ(ˎ(absolutePath));
        o_cfl.ˎ(ˋ(absolutePath));
        o_cfl.ˊ(absolutePath);
        o_cfl.ॱ(e.INNER_SDCARD);
        return o_cfl;
    }

    public static String ॱ(String str) {
        if (ContentManager.getInstant().getContext() == null || ContentManager.getInstant().getContext().getCacheDir() == null || ContentManager.getInstant().getContext().getCacheDir().getPath() == null) {
            return "";
        }
        File file = new File(ContentManager.getInstant().getContext().getCacheDir().getPath() + File.separator + "/Data/" + File.separator);
        if (!(file.exists() || file.mkdir())) {
            Logger.e("StorageManage", "cacheRoot mkdir failed!");
        }
        return file.getAbsolutePath() + File.separator + str;
    }

    public static String ʻ(Context context) {
        StorageVolume[] storageVolumeArr;
        String str;
        StorageManager storageManager = (StorageManager) context.getSystemService("storage");
        StorageVolume[] storageVolumeArr2 = new StorageVolume[0];
        try {
            Method method = StorageManager.class.getMethod("getVolumeList", new Class[0]);
            method.setAccessible(true);
            storageVolumeArr = (StorageVolume[]) method.invoke(storageManager, new Object[0]);
        } catch (Throwable e) {
            Logger.ˋ("StorageManage", "can not find method:getVolumeList", e);
            storageVolumeArr = storageVolumeArr2;
        } catch (Throwable e2) {
            Logger.ˋ("StorageManage", "can not find method:getVolumeList", e2);
            storageVolumeArr = storageVolumeArr2;
        } catch (Throwable e22) {
            Logger.ˋ("StorageManage", "can not find method:getVolumeList", e22);
            storageVolumeArr = storageVolumeArr2;
        }
        if (storageVolumeArr != null && storageVolumeArr.length > 0) {
            Method ॱ = ॱ();
            Method ˏ = ˏ();
            for (Object obj : storageVolumeArr) {
                boolean booleanValue;
                String str2;
                if (ॱ != null) {
                    try {
                        booleanValue = ((Boolean) ॱ.invoke(obj, new Object[0])).booleanValue();
                    } catch (Throwable e222) {
                        Logger.ˋ("StorageManage", "can not invoke method:getVolumeList", e222);
                        booleanValue = false;
                    } catch (Throwable e2222) {
                        Logger.ˋ("StorageManage", "can not invoke method:getVolumeList", e2222);
                    }
                    str = "";
                    str2 = (String) ˏ.invoke(obj, new Object[0]);
                    if (booleanValue && !str2.contains("usb")) {
                        return str2;
                    }
                }
                booleanValue = false;
                str = "";
                try {
                    str2 = (String) ˏ.invoke(obj, new Object[0]);
                } catch (Throwable e22222) {
                    Logger.ˋ("StorageManage", "can not invoke method:getPath", e22222);
                    str2 = str;
                } catch (Throwable e222222) {
                    Logger.ˋ("StorageManage", "can not invoke method:getPath", e222222);
                    str2 = str;
                }
                if (booleanValue) {
                }
            }
        }
        return null;
    }

    private static Method ॱ() {
        Method method;
        Throwable e;
        try {
            method = StorageVolume.class.getMethod("isRemovable", new Class[0]);
            try {
                method.setAccessible(true);
            } catch (NoSuchMethodException e2) {
                e = e2;
                Logger.ˋ("StorageManage", "can not find method:isRemovable", e);
                return method;
            }
        } catch (Throwable e3) {
            Throwable th = e3;
            method = null;
            e = th;
            Logger.ˋ("StorageManage", "can not find method:isRemovable", e);
            return method;
        }
        return method;
    }

    private static Method ˏ() {
        Method method;
        Throwable e;
        try {
            method = StorageVolume.class.getMethod("getPath", new Class[0]);
            try {
                method.setAccessible(true);
            } catch (NoSuchMethodException e2) {
                e = e2;
                Logger.ˋ("StorageManage", "can not find method:getPath", e);
                return method;
            }
        } catch (Throwable e3) {
            Throwable th = e3;
            method = null;
            e = th;
            Logger.ˋ("StorageManage", "can not find method:getPath", e);
            return method;
        }
        return method;
    }

    public static long ˎ(String str) {
        try {
            StatFs statFs = new StatFs(str);
            return statFs.getAvailableBlocksLong() * statFs.getBlockSizeLong();
        } catch (Throwable e) {
            Logger.ˋ("StorageManage", "path error", e);
            return 0;
        }
    }

    public static long ˋ(String str) {
        try {
            StatFs statFs = new StatFs(str);
            return statFs.getBlockCountLong() * statFs.getBlockSizeLong();
        } catch (Throwable e) {
            Logger.ˋ("StorageManage", "getTotalInternalMemorySize path error", e);
            return 0;
        }
    }
}
